package com.jwsoft.manager.core.integration.impl;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.IdcardUtil;
import com.alicp.jetcache.Cache;
import com.alicp.jetcache.anno.CacheType;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bifang.engine.assistant.core.annotation.ApiService;
import com.bifang.engine.assistant.core.annotation.OpApi;
import com.bifang.engine.assistant.core.annotation.SaveOplog;
import com.bifang.engine.assistant.core.enums.AuTypeEnum;
import com.bifang.engine.assistant.core.enums.BoolEnum;
import com.bifang.engine.assistant.core.enums.FuncTypeEnum;
import com.bifang.engine.assistant.core.exception.AppException;
import com.bifang.engine.assistant.core.utils.SessionUtil;
import com.bifang.engine.cache.jetcache.utils.JetCacheUtils;
import com.bifang.engine.data.core.util.PagerUtil;
import com.bifang.module.base.common.util.ApplicationContextHelper;
import com.bifang.module.base.common.util.CommonSecureUtil;
import com.bifang.module.base.core.helper.ApiModel;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jwsoft.manager.common.constant.EduCache;
import com.jwsoft.manager.common.enums.ComplaintTypeEnum;
import com.jwsoft.manager.common.vo.common.AreaControlVO;
import com.jwsoft.manager.common.vo.eduCompany.EduCompanyKeyVO;
import com.jwsoft.manager.common.vo.eduCompany.EduCompanyQueryVO;
import com.jwsoft.manager.common.vo.eduCompany.EduCompanyVO;
import com.jwsoft.manager.common.vo.eduSchool.EduSchoolVO;
import com.jwsoft.manager.common.vo.eduSocialSecurity.EduSocialSecurityVO;
import com.jwsoft.manager.common.vo.individuation.QySaveVO;
import com.jwsoft.manager.common.vo.individuation.QySearchVO;
import com.jwsoft.manager.core.dao.model.*;
import com.jwsoft.manager.core.dao.service.*;
import com.jwsoft.manager.core.integration.EduCompanyIntegration;
import com.jwsoft.manager.core.util.EduDesensitizeUtil;
import com.jwsoft.manager.core.util.EduEnrollClearCacheHelper;
import com.jwsoft.manager.core.util.EduHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

import java.lang.reflect.InvocationTargetException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;

/**
 * 企业信息管理业务实现类
 *
 * @author wangtao
 * @since 2022-12-28
 */
@ApiService(funcCode = "EduCompany", title = "企业信息管理")
public class EduCompanyIntegrationImpl implements EduCompanyIntegration {

    @Autowired
    public EduCompanyService eduCompanyService;
    @Autowired
    private EduStudentEnrollPreService eduStudentEnrollPreService;
    @Autowired
    private EduEnrollClearCacheHelper eduEnrollClearCacheHelper;
    @Autowired
    private EduHelper eduHelper;
    @Autowired
    private EduComplaintService eduComplaintService;
    @Autowired
    private EduSchoolService eduSchoolService;
    @Autowired
    private EduDataTaskDetailService eduDataTaskDetailService;

    @Autowired
    public EduhCompanyService eduhCompanyService;
    public static final String handleTable = "edu_company";
    @Override
    @OpApi(funcCode = "EduCompany0001", title = "企业信息管理分页查询", funcType = FuncTypeEnum.query)
    public PageInfo<EduCompanyVO> getList(EduCompanyQueryVO vo) {
        // 开启分页
        if (vo.getPageNum() == null || vo.getPageSize() == null) {
            //如果不传入分页参数，默认最大取1000条
            vo.setPageNum(1);
            vo.setPageSize(1000);
        }
        //取出脱敏字段，判断是否为空
        Boolean desensitizeFlag = vo.getDesensitizeFlag();
        if (desensitizeFlag == null){
            desensitizeFlag = true;
        }
        //根据任务判断是否当前年度处理过迁移数据
        Boolean queryHistoryFlag = eduDataTaskDetailService.verifyQueryHistory(vo.getYear(),handleTable);
        if (!queryHistoryFlag) {
            QueryWrapper<EduCompany> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda()
                    .eq(!ObjectUtils.isEmpty(vo.getTyxydm()),
                            EduCompany::getTyxydm,
                            vo.getTyxydm())
                    .eq(!ObjectUtils.isEmpty(vo.getFrdwmc()),
                            EduCompany::getFrdwmc,
                            vo.getFrdwmc())
                    .eq(!ObjectUtils.isEmpty(vo.getFrmc()),
                            EduCompany::getFrmc,
                            vo.getFrmc())
                    .eq(!ObjectUtils.isEmpty(vo.getYear()),
                            EduCompany::getYear,
                            vo.getYear())
                    .eq(!ObjectUtils.isEmpty(vo.getFrZjhm()),
                            EduCompany::getFrZjhm,
                            vo.getFrZjhm())
                    .eq(!ObjectUtils.isEmpty(vo.getSchoolId()),
                            EduCompany::getSchoolId,
                            vo.getSchoolId());
            PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
            List<EduCompany> list = eduCompanyService.list(queryWrapper);
            if (CollectionUtils.isEmpty(list)) {
                // 判断是否为空，为空则返回空参数
                return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
            }
            // 不为空则获取分页结果
            PageInfo<EduCompany> pageInfo = new PageInfo<>(list);
            // 返回参数需要通过common层的vo实体类，用该方法可以批量转换
            List<EduCompanyVO> resultList = Convert.toList(EduCompanyVO.class, pageInfo.getList());
            // 转义数据字典值
            // dictHelper.valueToName(resultList, Arrays.asList(DemoDictEnum.values()));

            //脱敏
            if (desensitizeFlag) {
                for (EduCompanyVO eduCompanyVO : resultList) {
                    eduCompanyVO.setTyxydm(EduDesensitizeUtil.desensitizeOther(eduCompanyVO.getTyxydm()));
                    eduCompanyVO.setDjzch(EduDesensitizeUtil.desensitizeOther(eduCompanyVO.getDjzch()));
                    eduCompanyVO.setZzjgdm(EduDesensitizeUtil.desensitizeOther(eduCompanyVO.getZzjgdm()));
                }
            }
            return PagerUtil.parsePagerVo(resultList, pageInfo);
        }else {
            // 迁移过后，判断是否加密
            Boolean encryptFlag = Boolean.TRUE.equals(eduDataTaskDetailService.verifyHistoryEncrypt(vo.getYear(), handleTable));
            //如果加密，把查询条件加密
            if (encryptFlag) {
                if (StringUtils.isNotBlank(vo.getTyxydm())){
                    vo.setTyxydm(CommonSecureUtil.sm4Encrypt(vo.getTyxydm()));
                }
                if (StringUtils.isNotBlank(vo.getDh())){
                    vo.setDh(CommonSecureUtil.sm4Encrypt(vo.getDh()));
                }
                if (StringUtils.isNotBlank(vo.getFrmc())){
                    vo.setFrmc(CommonSecureUtil.sm4Encrypt(vo.getFrmc()));
                }
                if (StringUtils.isNotBlank(vo.getFrZjhm())){
                    vo.setFrZjhm(CommonSecureUtil.sm4Encrypt(vo.getFrZjhm()));
                }
            }
            QueryWrapper<EduhCompany> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda()
                    .eq(!ObjectUtils.isEmpty(vo.getTyxydm()),
                            EduhCompany::getTyxydm,
                            vo.getTyxydm())
                    .eq(!ObjectUtils.isEmpty(vo.getFrdwmc()),
                            EduhCompany::getFrdwmc,
                            vo.getFrdwmc())
                    .eq(!ObjectUtils.isEmpty(vo.getFrmc()),
                            EduhCompany::getFrmc,
                            vo.getFrmc())
                    .eq(!ObjectUtils.isEmpty(vo.getYear()),
                            EduhCompany::getYear,
                            vo.getYear())
                    .eq(!ObjectUtils.isEmpty(vo.getFrZjhm()),
                            EduhCompany::getFrZjhm,
                            vo.getFrZjhm())
                    .eq(!ObjectUtils.isEmpty(vo.getSchoolId()),
                            EduhCompany::getSchoolId,
                            vo.getSchoolId());
            PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
            List<EduhCompany> list = eduhCompanyService.list(queryWrapper);
            if (CollectionUtils.isEmpty(list)) {
                // 判断是否为空，为空则返回空参数
                return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
            }
            // 不为空则获取分页结果
            PageInfo<EduhCompany> pageInfo = new PageInfo<>(list);
            // 返回参数需要通过common层的vo实体类，用该方法可以批量转换
            List<EduCompanyVO> resultList = Convert.toList(EduCompanyVO.class, pageInfo.getList());

            //解密
            for (EduCompanyVO eduCompanyVO : resultList) {
                if ("1".equals(eduCompanyVO.getEncryptFlag())) {
                    if (StringUtils.isNotBlank(eduCompanyVO.getTyxydm())) {
                        eduCompanyVO.setTyxydm(CommonSecureUtil.sm4Decrypt(eduCompanyVO.getTyxydm()));
                    }
                    if (StringUtils.isNotBlank(eduCompanyVO.getDh())) {
                        eduCompanyVO.setDh(CommonSecureUtil.sm4Decrypt(eduCompanyVO.getDh()));
                    }
                    if (StringUtils.isNotBlank(eduCompanyVO.getFrmc())) {
                        eduCompanyVO.setFrmc(CommonSecureUtil.sm4Decrypt(eduCompanyVO.getFrmc()));
                    }
                    if (StringUtils.isNotBlank(eduCompanyVO.getFrZjhm())) {
                        eduCompanyVO.setFrZjhm(CommonSecureUtil.sm4Decrypt(eduCompanyVO.getFrZjhm()));
                    }
                }
            }
            // 转义数据字典值
            // dictHelper.valueToName(resultList, Arrays.asList(DemoDictEnum.values()));

            //脱敏
            if (desensitizeFlag) {
                for (EduCompanyVO eduCompanyVO : resultList) {
                    eduCompanyVO.setTyxydm(EduDesensitizeUtil.desensitizeOther(eduCompanyVO.getTyxydm()));
                    eduCompanyVO.setDjzch(EduDesensitizeUtil.desensitizeOther(eduCompanyVO.getDjzch()));
                    eduCompanyVO.setZzjgdm(EduDesensitizeUtil.desensitizeOther(eduCompanyVO.getZzjgdm()));
                }
            }
            return PagerUtil.parsePagerVo(resultList, pageInfo);
        }
    }

    @Override
    @OpApi(funcCode = "EduCompany0002", title = "企业信息管理根据主键查询详情", funcType = FuncTypeEnum.query)
    public EduCompanyVO getById(EduCompanyKeyVO vo) {
        //判断是否迁移过
        EduCompanyVO result;
        Boolean queryHistoryFlag = Boolean.TRUE.equals(eduDataTaskDetailService.verifyQueryHistory(vo.getYear(), handleTable));
        if (!queryHistoryFlag) {
            // 没有迁移查询
            EduCompany entity = eduCompanyService.getById(vo.getCompanyId());
            if (ObjectUtils.isEmpty(entity)) {
                throw new AppException("查询不到详细信息!");
            }
            result = Convert.convert(EduCompanyVO.class, entity);
        } else {
            EduhCompany eduhCompany = eduhCompanyService.getById(vo.getCompanyId());

            if (ObjectUtils.isEmpty(eduhCompany)) {
                throw new AppException("查询不到详细信息!");
            }
            //解密
            if ("1".equals(eduhCompany.getEncryptFlag())) {
                if (StringUtils.isNotBlank(eduhCompany.getTyxydm())){
                    eduhCompany.setTyxydm(CommonSecureUtil.sm4Decrypt(eduhCompany.getTyxydm()));
                }
                if (StringUtils.isNotBlank(eduhCompany.getDh())){
                    eduhCompany.setDh(CommonSecureUtil.sm4Decrypt(eduhCompany.getDh()));
                }
                if (StringUtils.isNotBlank(eduhCompany.getFrmc())){
                    eduhCompany.setFrmc(CommonSecureUtil.sm4Decrypt(eduhCompany.getFrmc()));
                }
                if (StringUtils.isNotBlank(eduhCompany.getFrZjhm())){
                    eduhCompany.setFrZjhm(CommonSecureUtil.sm4Decrypt(eduhCompany.getFrZjhm()));
                }
            }
            result = Convert.convert(EduCompanyVO.class, eduhCompany);
        }

        return result;
    }

    /**
     * 保存前统一校验
     */
    @Override
    @OpApi(funcCode = "EduCompany0003", title = "企业信息管理保存前校验", funcType = FuncTypeEnum.other, checkPrivilege = BoolEnum.FALSE)
    public void checkSave(EduCompanyVO vo) {
        if(!IdcardUtil.isValidCard(vo.getFrZjhm())){
            throw new AppException("法定代表人证件号码有误！");
        }
        //主键为空为新增校验
        //1、通年度同统一社会信用代码，不能重复
        LambdaQueryWrapper<EduCompany> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(EduCompany::getDel, 0);
        queryWrapper.eq(EduCompany::getYear, vo.getYear());
        queryWrapper.eq(EduCompany::getTyxydm, vo.getTyxydm());
        if (!ObjectUtils.isEmpty(vo.getCompanyId())) {
            queryWrapper.ne(EduCompany::getCompanyId, vo.getCompanyId());
        }
        queryWrapper.eq(EduCompany::getSchoolId,vo.getSchoolId());
        if (eduCompanyService.count(queryWrapper) != 0) {
            throw new AppException("该单位存在重复数据，请核对!");
        }
    }

    @Override
    @OpApi(funcCode = "EduCompany0004", title = "企业信息管理新增", funcType = FuncTypeEnum.insert)
    @SaveOplog(
            operationType = "EduCompany0004",
            operationName = "企业信息管理新增",
            dataType = "companyId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public EduCompanyVO add(EduCompanyVO vo) {
        //保存前校验
        checkSave(vo);
        //保存数据
        EduCompany entity = Convert.convert(EduCompany.class, vo);
        eduCompanyService.save(entity);
        //将主键设置回vo使操作日志可以取到
        vo.setCompanyId(entity.getCompanyId());
        clearCache(entity.getFrZjhm());
        return vo;
    }

    @Override
    @OpApi(funcCode = "EduCompany0005", title = "企业信息管理修改", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "EduCompany0005",
            operationName = "企业信息管理修改",
            dataType = "companyId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public EduCompanyVO edit(EduCompanyVO vo) {
        Boolean queryHistoryFlag = Boolean.TRUE.equals(eduDataTaskDetailService.verifyQueryHistory(vo.getYear(), handleTable));
        if (queryHistoryFlag) {
            throw new AppException("历史数据无法修改");
        }
        if (ObjectUtils.isEmpty(vo.getCompanyId())) {
            throw new AppException("传入需要修改的主键不能为空!");
        }
        EduCompany oldEntity = eduCompanyService.getById(vo.getCompanyId());
        if (ObjectUtils.isEmpty(oldEntity)) {
            throw new AppException("查询不到需要修改的信息!");
        }
        //保存前校验
        checkSave(vo);
        //保存数据
        EduCompany entity = Convert.convert(EduCompany.class, vo);
        eduCompanyService.updateById(entity);
        clearCache(entity.getFrZjhm());
        return vo;
    }

    @Override
    @OpApi(funcCode = "EduCompany0006", title = "企业信息管理根据主键删除", funcType = FuncTypeEnum.delete)
    @SaveOplog(
            operationType = "EduCompany0006",
            operationName = "企业信息管理删除",
            dataType = "companyId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public void del(EduCompanyKeyVO vo) {
        if (ObjectUtils.isEmpty(vo.getCompanyId())) {
            throw new AppException("传入需要删除的数据主键不能为空!");
        }
        EduCompany entity = eduCompanyService.getById(vo.getCompanyId());
        if (ObjectUtils.isEmpty(entity)) {
            throw new AppException("未找到需要删除的信息!");
        }
        eduCompanyService.removeById(vo.getCompanyId());
        clearCache(entity.getFrZjhm());
    }
    //清除缓存
    private void clearCache(String idcard){
        //查询人员
        if(StringUtils.isBlank(idcard)){
            return;
        }

        QueryWrapper<EduStudentEnrollPre> queryPreWrapper=new QueryWrapper<>();
        queryPreWrapper.lambda().select(EduStudentEnrollPre::getStudentEnrollPreId,EduStudentEnrollPre::getIdcard,EduStudentEnrollPre::getFatherIdcard,EduStudentEnrollPre::getMotherIdcard)
                .eq(EduStudentEnrollPre::getYear,eduHelper.thisYear())
                .and( wrapper -> {
                    wrapper.eq(EduStudentEnrollPre::getIdcard, idcard)
                            .or()
                            .eq(EduStudentEnrollPre::getFatherIdcard, idcard)
                            .or()
                            .eq(EduStudentEnrollPre::getMotherIdcard, idcard);
                });
        List<EduStudentEnrollPre> list=eduStudentEnrollPreService.list(queryPreWrapper);
        if (CollectionUtils.isEmpty(list)){
            return;
        }
        for (EduStudentEnrollPre pre:list) {
            //企业
            eduEnrollClearCacheHelper.clearCacheMyEnrollPreQy(pre.getFatherIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnrollPreQy(pre.getMotherIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnrollPreQy(pre.getIdcard());
            eduEnrollClearCacheHelper.clearCachePreBefore(pre.getStudentEnrollPreId());
        }
    }
    @Override
    @OpApi(funcCode = "EduCompany0007", title = "获取企业信息并保存", funcType = FuncTypeEnum.edit)
    public List<EduCompanyVO> getCompanyAndSave(QySaveVO vo) {
        if (StringUtils.isBlank(vo.getAreaCode())) {
            vo.setAreaCode(eduHelper.thisAreaCode());
        }
        ApiModel apiModel = eduHelper.getEduFunc("saveQyInterfaceData", vo.getAreaCode());
        try {
            Object bean = ApplicationContextHelper.getBean(apiModel.getBeanName());
            if (null != bean) {
                List<EduCompanyVO> list = (List<EduCompanyVO>) apiModel.getMethod().invoke(bean, vo);
                if (!CollectionUtils.isEmpty(list)) {
                    return list;
                }
            } else {
                throw new AppException("未查询到方法");
            }
        } catch (AppException e ){
            throw e;
        }catch (InvocationTargetException e ){
            try{
                AppException exception= (AppException) e.getTargetException();
                throw new AppException(exception.getMsg(),e.getTargetException());
            }catch (Exception ex){
                throw new AppException(e.getCause().getMessage(),e.getTargetException());
            }

        }catch (Exception e ){
            throw new AppException( e.getMessage(),e);
        }
        return new ArrayList<>();
    }

    @Override
    @OpApi(funcCode = "EduCompany0008", title = "获取企业信息", funcType = FuncTypeEnum.query)
    public List<EduCompanyVO> getCompany(QySearchVO vo) {
        if (StringUtils.isBlank(vo.getAreaCode())) {
            vo.setAreaCode(eduHelper.thisAreaCode());
        }
        ApiModel apiModel = eduHelper.getEduFunc("queryQyInterfaceData", vo.getAreaCode());
        try {
            Object bean = ApplicationContextHelper.getBean(apiModel.getBeanName());
            if (null != bean) {
                List<EduCompanyVO> list = (List<EduCompanyVO>) apiModel.getMethod().invoke(bean, vo);
                if (!CollectionUtils.isEmpty(list)) {
                    return list;
                } else {
                    throw new AppException("未查询到企业信息，请手动输入！");
                }
            } else {
                throw new AppException("未查询到方法");
            }
        } catch (AppException e ){
            throw e;
        }catch (InvocationTargetException e ){
            try{
                AppException exception= (AppException) e.getTargetException();
                throw new AppException(exception.getMsg(),e.getTargetException());
            }catch (Exception ex){
                throw new AppException(e.getCause().getMessage(),e.getTargetException());
            }

        }catch (Exception e ){
            throw new AppException( e.getMessage(),e);
        }
    }

    @Override
    @OpApi(funcCode = "EduCompany0009", title = "家长端获取我的企业信息", funcType = FuncTypeEnum.query)
    public List<EduCompanyVO> getAppCompanyList(AreaControlVO vo) {
        String idcard=SessionUtil.getSessionInfo().getIdcard();
        if(StringUtils.isBlank(idcard)){
            throw new AppException("用户的证件号码不能为空");
        }
        String key=idcard;
        Cache<String, List<EduCompanyVO>> cache = JetCacheUtils.create(EduCache.EDU_MY_ENROLL_PRE_QY, CacheType.BOTH, Duration.ofHours(6), Duration.ofSeconds(20));
        List<EduCompanyVO> value=  cache.get(key);
        if(value!=null){
            return value;
        }
        if(StringUtils.isBlank(vo.getAreaCode())){
            vo.setAreaCode(eduHelper.thisAreaCode());
        }
        Integer year = eduHelper.thisYear();


        QueryWrapper<EduStudentEnrollPre> studentEnrollPreQueryWrapper = new QueryWrapper<>();
        studentEnrollPreQueryWrapper
                .lambda()
                .eq(EduStudentEnrollPre::getYear, year)
                .and(
                        wrapper -> {
                            wrapper.eq(EduStudentEnrollPre::getFatherIdcard, idcard)
                                    .or()
                                    .eq(EduStudentEnrollPre::getIdcard, idcard)
                                    .or()
                                    .eq(EduStudentEnrollPre::getMotherIdcard, idcard);
                        }).orderByAsc(EduStudentEnrollPre::getIdcard);
        List<EduStudentEnrollPre> queryList =
                eduStudentEnrollPreService.list(studentEnrollPreQueryWrapper);
        if(CollectionUtils.isEmpty(queryList)){
            return new ArrayList<>();
        }
        List<String> idcardList=new ArrayList<>();
        for(EduStudentEnrollPre eduStudentEnrollPre:queryList){
            if(StringUtils.isNotBlank(eduStudentEnrollPre.getIdcard())&&!idcardList.contains(eduStudentEnrollPre.getIdcard())){
                idcardList.add(eduStudentEnrollPre.getIdcard());
            }
            if(StringUtils.isNotBlank(eduStudentEnrollPre.getFatherIdcard())&&!idcardList.contains(eduStudentEnrollPre.getFatherIdcard())){
                idcardList.add(eduStudentEnrollPre.getFatherIdcard());
            }
            if(StringUtils.isNotBlank(eduStudentEnrollPre.getMotherIdcard())&&!idcardList.contains(eduStudentEnrollPre.getMotherIdcard())){
                idcardList.add(eduStudentEnrollPre.getMotherIdcard());
            }
        }
        QueryWrapper<EduCompany> companyQueryWrapper = new QueryWrapper<>();
        companyQueryWrapper.lambda().eq(EduCompany::getYear, year)
                .eq(EduCompany::getAreaCode, vo.getAreaCode())
                .in(EduCompany::getFrZjhm, idcardList).orderByAsc(EduCompany::getFrZjhm);
        List<EduCompany> companyList = eduCompanyService.list(companyQueryWrapper);
        if (!CollectionUtils.isEmpty(companyList)) {
            List<EduCompanyVO> companyVOList = new ArrayList<>();
            for(EduCompany company:companyList) {
                EduCompanyVO companyVO = Convert.convert(EduCompanyVO.class, company);
                QueryWrapper<EduComplaint> queryWrapper=new QueryWrapper<>();
                queryWrapper.lambda().select(EduComplaint::getHandleStatus).eq(EduComplaint::getType, ComplaintTypeEnum.sb.getType())
                        .eq(EduComplaint::getHandleStatus,BoolEnum.FALSE.getType())
                        .eq(EduComplaint::getOtherId,companyVO.getCompanyId());
                List<EduComplaint> complaints=eduComplaintService.list(queryWrapper);
                if(!CollectionUtils.isEmpty(complaints)){
                    companyVO.setQyHandleStatus(complaints.get(0).getHandleStatus());
                }
                if(StringUtils.isNotBlank(companyVO.getSchoolId())){
                    EduSchoolVO eduSchool=eduSchoolService.getDetail(companyVO.getSchoolId());
                    if(eduSchool!=null){
                        companyVO.setSchoolName(eduSchool.getSchoolName());
                    }
                }
                companyVOList.add(companyVO);
            }
            cache.put(key,companyVOList);
            return companyVOList;
        }
        cache.put(key,new ArrayList<>());
        return new ArrayList<>();
    }
}
